package me.work.pay.jsyl.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.work.pay.jsyl.R;
import me.work.pay.jsyl.app.Constants;
import me.work.pay.jsyl.di.component.DaggerOrderListComponent;
import me.work.pay.jsyl.mvp.contract.OrderListContract;
import me.work.pay.jsyl.mvp.model.AppModel;
import me.work.pay.jsyl.mvp.model.entity.OrderNormalData;
import me.work.pay.jsyl.mvp.model.entity.StatisticsData;
import me.work.pay.jsyl.mvp.presenter.OrderListPresenter;
import me.work.pay.jsyl.mvp.ui.holder.AutoBaseViewHolder;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * 订单列表页
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 09/14/2020 08:45
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class OrderListLandActivity extends BaseActivity<OrderListPresenter> implements OrderListContract.View {
    @Inject
    @Named("land")
    BaseQuickAdapter<OrderNormalData, AutoBaseViewHolder> mAdapter;
    @Inject
    List<OrderNormalData> mList;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.tv1)
    TextView tv1;
    @BindView(R.id.tv2)
    TextView tv2;
    @BindView(R.id.tv3)
    TextView tv3;
    public static OrderListLandActivity main;
    @BindView(R.id.load_view)
    View load_view;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerOrderListComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {

        return R.layout.activity_order_list_land; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    private void init_page() {
        SPUtils.getInstance().put(Constants.sp_page_value, "4");
    }

    @Override
    protected void onResume() {
        super.onResume();
        init_page();
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        main = this;
        init_page();
        rv.setAdapter(mAdapter);

        rv.setLayoutManager(new LinearLayoutManager(this));
        mPresenter.get_orders();
    }

    @Override
    public void load_success(StatisticsData statisticsData, List<OrderNormalData> data) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = new Date(System.currentTimeMillis());
        tv1.setText(simpleDateFormat.format(date));
        tv2.setText("今日收款" + statisticsData.number + "笔\n\n\n合计");
        tv3.setText("￥" + statisticsData.total);
        mAdapter.setNewData(data);
        load_view.setVisibility(View.GONE);
    }

    @Override
    public void load_error() {
        load_view.setVisibility(View.GONE);
//        ToastUtils.showShort("请");
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public Activity getActivity() {
        return this;
    }


}
